fix(plausible): honor scriptInput.src in bundle.resolve for self-hosted#775
Conversation
The build-time bundle transformer calls `bundle.resolve()` with the merged registry config to determine which URL to download. For Plausible, the resolver only inspected `scriptId`/`extension` and always returned `plausible.io`, so self-hosted users hit fetch failures (e.g. `https://plausible.io/js/pa-<id>.js` → 404) at build time and runtime overrides were never reached. Honor `options.scriptInput?.src` first so self-hosted Plausible bundles from the user-configured origin. Fixes #768
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds self-hosted Plausible support to the bundle resolver. The implementation checks if Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/script/src/registry.ts`:
- Around line 307-308: The current check allows whitespace-only scriptInput.src
because it only tests userSrc.length; update the logic around userSrc (derived
from scriptInput.src) to use a trimmed check and return the trimmed value:
require typeof userSrc === 'string' && userSrc.trim().length > 0 before
returning, and return userSrc.trim() so whitespace-only values are treated as
unset and genuine URLs are normalized. This change should be made in the same
block that currently contains the if (typeof userSrc === 'string' &&
userSrc.length > 0) return userSrc check in registry.ts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 361c9806-cb9b-45d9-b51c-a30d743cb180
📒 Files selected for processing (2)
packages/script/src/registry.tstest/unit/plausible-bundle-resolve.test.ts
🔗 Linked issue
Resolves #768
❓ Type of change
📚 Description
Self-hosted Plausible was broken in v1.0.6. The bundle transformer (
packages/script/src/plugins/transform.ts) callsbundle.resolve()with the merged registry config to determine which URL to download at build time. Plausible's resolver only looked atscriptId/extension, always returningplausible.io, so:404/fetch failedagainsthttps://plausible.io/js/pa-<id>.jsduring bundling.proxy: false, the build error went away but the rewritten script still pointed atplausible.io, so the runtimescriptInput.srcoverride never took effect.Bundle resolver now honors
options.scriptInput?.srcfirst, so self-hosted Plausible bundles (and runs) against the user-configured origin.✅ Verification
pnpm vitest run --project unit test/unit/plausible-bundle-resolve.test.ts(new regression test)pnpm vitest run --project unit— 675 passed, 2 todonuxt-starter-sapvn3tf) builds without hittingplausible.io